﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace TomAndJerryMidnightSnack
{

    class GameOverScreen : GameScreen
    {

        Texture2D backgroundTexture;
        Texture2D instructionTexture;
        Texture2D playTexture;

        Vector2 instructionPosition;
        Vector2 playPosition;
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameOverScreen()
            : base()
        {
            //sound effect for game
            //AudioManager.PushMusic("LoseTheme",false);
            this.Exiting += new EventHandler(HomeScreen_Exiting);
        }


        void HomeScreen_Exiting(object sender, EventArgs e)
        {
            //stop music
            //AudioManager.PopMusic();
        }

        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;

            backgroundTexture = content.Load<Texture2D>(@"homepage");
            instructionTexture = content.Load<Texture2D>(@"Buttons\instruction");
            playTexture = content.Load<Texture2D>(@"Buttons\play");

            instructionPosition = new Vector2(100, 36);
            playPosition = new Vector2(100, 480);
        }

        /// <summary>
        /// UnloadContent
        /// </summary>

        public override void UnloadContent()
        {
            base.UnloadContent();
        }

        /// <summary>
        /// Handles user input.
        /// </summary>
        public override void HandleInput()
        {
            int touchMode = 0;
            if (InputManager.IsButtonClicked(new Rectangle(
                (int)instructionPosition.X - instructionTexture.Height, (int)instructionPosition.Y,
                (int)(instructionTexture.Height),
                (int)(instructionTexture.Width))))
            {
                touchMode = 1;
            }
            else if (InputManager.IsButtonClicked(new Rectangle(
                (int)playPosition.X - playTexture.Height, (int)playPosition.Y,
                (int)(playTexture.Height),
                (int)(playTexture.Width))))
            {
                touchMode = 2;
            }
            GameScreen screen = null;
            switch (touchMode)
            {
                case 1:
                    //screen = new Instruction1();
                    break;
                case 2:
                    //screen = new Level1Screen();
                    break;
                default:
                    break;
            }
            if (screen != null)
            {
                ExitScreen();
                ScreenManager.AddScreen(screen);
            }
            base.HandleInput();
        }

        /// <summary>
        /// Updates the menu.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }


        /// <summary>
        /// Draws the menu.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            ScreenManager.GraphicsDevice.SetRenderTarget(ScreenManager.FinalImageTarget);
            ScreenManager.GraphicsDevice.Clear(Color.CornflowerBlue);

            // we will do all of our drawing here
            ScreenManager.GraphicsDevice.SetRenderTarget(null);

            spriteBatch.Begin();
            spriteBatch.Draw(backgroundTexture, new Vector2(480, 0), null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.Draw(playTexture, playPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            //spriteBatch.Draw(instruction, instructionPosition,null, Color.White, MathHelper.PiOver2, Vector2.Zero, new Vector2(200/169,200/82), SpriteEffects.None, 0f);
            spriteBatch.Draw(instructionTexture, instructionPosition, null, Color.White, MathHelper.PiOver2, Vector2.Zero, Vector2.One, SpriteEffects.None, 0f);
            spriteBatch.End();
        }
    }
}
